<template>
  <div class="index-container">
    <div class="main-header">
      <el-row>
        <el-col :xs="8"
                :sm="8"
                :md="8"
                :lg="8"
                :xl="8">
          <el-button type="primary"
                     icon="el-icon-plus"
                     class="sureBtn"
                     size="medium"
                     @click="handleAdd">
            入 住
          </el-button>
          <el-button type="success"
                     icon="el-icon-search"
                     class="sureBtn"
                     size="medium"
                     @click="handleCheck">
            编辑/查看
          </el-button>
          <el-button type="primary"
                     size="medium"
                     icon="el-icon-plus"
                     @click="handleOldLeave">
            老人请假
          </el-button>
          <el-button type="danger"
                     class="setBtn"
                     icon="el-icon-delete"
                     size="medium"
                     @click="handleDelete">
            删 除
          </el-button>
        </el-col>
        <el-col style="margin-top: 10px;"
                :xs="24"
                :sm="24"
                :md="24"
                :lg="24"
                :xl="24">
          <div class="search">
            <el-row :gutter="20">
              <el-col :xs="4"
                      :sm="4"
                      :md="4"
                      :lg="4"
                      :xl="4">
                <el-input v-model="selectForm.name"
                          size="small"
                          placeholder="老人姓名"
                          clearable></el-input>
              </el-col>
              <el-col :xs="4"
                      :sm="4"
                      :md="4"
                      :lg="4"
                      :xl="4">
                <el-select v-model="selectForm.in_type"
                           clearable
                           placeholder="请选择"
                           filterable
                           style="width: 100%;"
                           @change="handleIntype">
                  <el-option :key="1"
                             label="智慧中心"
                             :value="1"></el-option>
                  <el-option :key="2"
                             label="养护中心"
                             :value="2"></el-option>
                  <el-option :key="3"
                             label="老年公寓"
                             :value="3"></el-option>
                </el-select>
              </el-col>

              <el-col :xs="4"
                      :sm="4"
                      :md="4"
                      :lg="4"
                      :xl="4">
                <el-input v-model="selectForm.mobile"
                          size="small"
                          placeholder="联系方式"
                          clearable></el-input>
              </el-col>
              <el-col :xs="6"
                      :sm="6"
                      :md="6"
                      :lg="6"
                      :xl="6">
                <el-date-picker v-model="selectForm.start_time"
                                value-format="yyyy-MM-dd"
                                format="yyyy 年 MM 月 dd 日"
                                placeholder="查询开始"
                                size="small"
                                :picker-options="dataPickerBeforeTodayOptions"
                                style="width: 45%;"></el-date-picker>
                <span style="padding: 0 10px;">~</span>
                <el-date-picker v-model="selectForm.end_time"
                                value-format="yyyy-MM-dd"
                                format="yyyy 年 MM 月 dd 日"
                                placeholder="查询结束"
                                size="small"
                                :picker-options="dataPickerBeforeTodayOptions"
                                style="width: 45%;"></el-date-picker>
                &nbsp;
              </el-col>
              <el-col :xs="4"
                      :sm="4"
                      :md="4"
                      :lg="4"
                      :xl="4">
                <el-input v-model="selectForm.id_card"
                          size="small"
                          placeholder="身份证"
                          clearable></el-input>
              </el-col>
              <el-col :xs="2"
                      :sm="2"
                      :md="2"
                      :lg="2"
                      :xl="2">
                <el-button size="small"
                           type="primary"
                           icon="el-icon-search"
                           class="fr"
                           @click="search">
                  搜索
                </el-button>
              </el-col>
            </el-row>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="main-content">
      <app-table ref="dataTable"
                 :page-data="pageData"
                 :table-columns="tableColumns"
                 @current-change="handleCurrentChange"
                 @handleCheckedRows="handleCheckedRows"
                 @leave="leave"
                 @elderback="elderback"
                 @leavedetail="leavedetail"
                 @consumption="consumption"
                 @accountTk="accountTk"
                 @handleGetQuestions="handleGetQuestions"
                 @blllDetail="blllDetail"></app-table>
    </div>
    <!-- 入住登记 -->
    <el-dialog title="入住登记"
               :visible.sync="dialogVisible"
               width="90%"
               :before-close="closeDialog"
               :close-on-click-modal="false"
               class="dialogForm">
      <div class="dialog-main">
        <common-form :key="key"
                     :gutter="30"
                     :datas="formData"
                     @show="showdil"
                     @handleMap="handleMap"></common-form>
      </div>
    </el-dialog>
    <!-- 入住登记end -->
    <!-- 离院结算 -->
    <el-dialog title="办理离院"
               :visible.sync="dialogVisibleLive"
               width="35%"
               :before-close="closeDialogLive"
               :close-on-click-modal="false"
               class="dialogForm">
      <div class="dialog-main">
        <leave-account-form :key="key3"
                            :data="formData"
                            :data-obj="accoutResult"
                            @changeLeave="changeLeave"
                            @cancelLeave="cancelLeave"
                            @checkDetail="checkDetail"></leave-account-form>
      </div>
    </el-dialog>
    <!-- 离院结算end -->
    <!-- 离院结算 -->
    <el-dialog title="费用明细"
               :visible.sync="dialogVisibleDetailLive"
               width="60%"
               :before-close="closeDialogLive"
               :close-on-click-modal="false"
               class="dialogForm">
      <div class="dialog-main">
        <leave-detail-form :key="key4"
                           :data="formData"
                           @cancelLeave="cancelLeave"
                           @checkDetail="checkDetail"></leave-detail-form>
      </div>
    </el-dialog>
    <!-- 离院结算end -->
    <!-- 地图 -->
    <el-dialog title="选择地址"
               :visible.sync="mapVisible"
               width="60%"
               :before-close="closeMap"
               :close-on-click-modal="false"
               class="dialogForm">
      <div class="dialog-main">
        <app-map :key="key2"
                 ref="map"
                 :keyword="keyword"
                 @result="result"></app-map>
      </div>
    </el-dialog>
    <!-- 地图end -->
    <!-- 账单汇总 -->
    <el-dialog title="账单汇总"
               :visible.sync="dialogVisibleNurse"
               width="60%"
               :before-close="closeDialogNurse"
               :close-on-click-modal="false"
               class="dialogForm">
      <account-detail :key="key2"
                      :data="formAccountData"
                      :data-obj="accoutResult"
                      :base-account="baseAccount"
                      @accoutSearch="accoutSearch"></account-detail>
    </el-dialog>
    <!-- 账单汇总end -->
    <!-- 老人请假 start -->
    <el-dialog title="老人请假"
               :visible.sync="dialogVisibleLeave"
               width="35%"
               :before-close="closeDialogLeave"
               :close-on-click-modal="false"
               class="dialogForm">
      <div class="dialog-main">
        <leave-form :key="key3"
                    :e_id="leave_eid"
                    @handleCancleLeave="handleCancleLeave"></leave-form>
      </div>
    </el-dialog>
    <!-- 老人请假 end -->

    <!-- 账单明细 -->
    <el-dialog title="账单明细"
               :visible.sync="dialogVisibleAccount"
               width="60%"
               :before-close="closeDialogAccount"
               :close-on-click-modal="false"
               class="dialogForm">
      <div class="dialog-main">
        <div class="table-do">
          <el-row>
            <el-col :xs="8"
                    :sm="8"
                    :md="8"
                    :lg="8"
                    :xl="8">
              <el-button type="primary"
                         icon="el-icon-plus"
                         class="sureBtn"
                         size="mini"
                         @click="handleAddAccount">
                新增
              </el-button>
              <!-- <el-button
                type="success"
                icon="el-icon-plus"
                class="sureBtn"
                size="mini"
                @click="handleSettlement"
              >
                结算
              </el-button> -->
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :xs="5"
                    :sm="5"
                    :md="5"
                    :lg="5"
                    :xl="5">
              <div style="margin-top: 15px;">
                <span v-if="accountPageData.sum">
                  总计费用：{{accountPageData.sum}}
                </span>
              </div>
            </el-col>
            <el-col :xs="5"
                    :sm="5"
                    :md="5"
                    :lg="5"
                    :xl="5">
              <el-select v-model="accountSelectForm.type"
                         size="medium"
                         clearable
                         placeholder="请选择账单类型"
                         filterable
                         style="width: 100%;">
                <el-option :key="0"
                           label="消费"
                           :value="1"></el-option>
                <el-option :key="1"
                           label="交费"
                           :value="2"></el-option>
              </el-select>
            </el-col>
            <el-col :xs="12"
                    :sm="12"
                    :md="12"
                    :lg="12"
                    :xl="12">
              <el-date-picker v-model="accountSelectForm.start_time"
                              value-format="yyyy-MM-dd"
                              format="yyyy 年 MM 月 dd 日"
                              placeholder="查询开始"
                              size="medium"
                              :picker-options="dataPickerBeforeTodayOptions"
                              style="width: 45%;"></el-date-picker>
              <span style="padding: 0 10px;">~</span>
              <el-date-picker v-model="accountSelectForm.end_time"
                              value-format="yyyy-MM-dd"
                              format="yyyy 年 MM 月 dd 日"
                              placeholder="查询结束"
                              size="medium"
                              :picker-options="dataPickerBeforeTodayOptions"
                              style="width: 45%;"></el-date-picker>
              &nbsp;
            </el-col>
            <el-col :xs="2"
                    :sm="2"
                    :md="2"
                    :lg="2"
                    :xl="2">
              <el-button size="medium"
                         type="primary"
                         icon="el-icon-search"
                         class="fr"
                         @click="accountsearch">
                搜索
              </el-button>
            </el-col>
          </el-row>
        </div>
        <el-table :data="accountPageData.list"
                  stripe
                  :cell-class-name="set_cell_style2"
                  :header-cell-style="{ backgroundColor: '#409EFF', color: '#fff' }"
                  @selection-change="handleSelectionChange">
          <el-table-column type="selection"
                           width="55"></el-table-column>
          <el-table-column v-for="(item, index) in tableColumns3"
                           :key="index"
                           :prop="item.prop"
                           :label="item.label"
                           :width="item.width"
                           :formatter="item.formatter"
                           :filters="item.filters"
                           :class-name="item.className"
                           :show-overflow-tooltip="true"></el-table-column>
          <el-table-column label="操作"
                           width="150">
            <template slot-scope="scope">
              <el-button size="mini"
                         type="danger"
                         @click="handleCancelAccount(scope.row.id)">
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination background
                       :current-page="accountPageData.page"
                       layout="total, prev, pager, next, jumper"
                       :total="accountPageData.total"
                       :page-size="accountPageData.page_size"
                       @current-change="handleCurrentChange1"></el-pagination>

      </div>
      <el-dialog width="40%"
                 title="新增账单"
                 :visible.sync="innerVisibleAccount"
                 :before-close="closeVisibleAccount"
                 append-to-body
                 :close-on-click-modal="false">
        <el-form ref="accountForm"
                 :model="accountForm"
                 :rules="rules"
                 label-width="100px"
                 class="demo-ruleForm"
                 size="medium">
          <el-row>
            <el-col :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="24"
                    :xl="24">
              <el-form-item label="账单类型"
                            prop="type">
                <el-select v-model="accountForm.type"
                           size="medium"
                           clearable
                           placeholder="请选择账单类型"
                           filterable
                           style="width: 100%;">
                  <el-option :key="0"
                             label="消费"
                             :value="1"></el-option>
                  <el-option :key="1"
                             label="交费"
                             :value="2"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="24"
                    :xl="24">
              <el-form-item label="账单名称"
                            prop="title">
                <el-input v-model="accountForm.title"
                          placeholder="请输入账单名称"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="24"
                    :xl="24">
              <el-form-item label="金额"
                            prop="amount">
                <el-input v-model="accountForm.amount"
                          placeholder="请输入账单金额"
                          type="number"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="24"
                    :xl="24">
              <el-form-item label="添加时间"
                            prop="action_time">
                <el-date-picker v-model="accountForm.action_time"
                                value-format="yyyy-MM-dd"
                                format="yyyy 年 MM 月 dd 日"
                                placeholder="选择日期时间"
                                style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="24"
                    :xl="24">
              <el-form-item label="请输入账单明细"
                            prop="remark">
                <el-input v-model="accountForm.remark"
                          :rows="5"
                          type="textarea"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div class="form-footer"
             style="padding-left: 100px;">
          <el-button type="primary"
                     class="sureBtn"
                     size="mini"
                     @click="saveAccount">
            提 交
          </el-button>
          <el-button type="info"
                     class="setBtn"
                     size="mini"
                     @click="canceAccount('accountForm')">
            取 消
          </el-button>
        </div>
      </el-dialog>
    </el-dialog>
    <!-- 记账明细end -->
    <div id="mapStyle"></div>
    <el-dialog width="700px"
               title="账单"
               :visible.sync="accountTable"
               append-to-body
               :close-on-click-modal="false">
      <div class="printBtn">
        <el-button type="primary"
                   @click="handlePrint">打印</el-button>
      </div>
      <div ref="print"
           class="dialog-main">
        <el-divider content-position="left">入院费用</el-divider>
        <div class="baseSAccount accountTable">
          <table class="table"
                 width="100%">
            <tr>
              <td>床位费</td>
              <td>{{ baseAccount.bed.price }}元</td>
              <td>护理费</td>
              <td>{{ baseAccount.care.price }}元</td>
            </tr>
            <tr>
              <td>管理费</td>
              <td>{{ baseAccount.care.manage_price }}元</td>
              <td>用餐费</td>
              <td>{{ baseAccount.meal.price }}元</td>
            </tr>
            <tr>
              <td>日用品费</td>
              <td>{{ baseAccount.other_amount }}元</td>
              <td>空调以及取暖费</td>
              <td>{{ baseAccount.power_amount }}元</td>
            </tr>
            <tr>
              <td>医疗备用金</td>
              <td>{{ baseAccount.medical_amount }}元</td>
              <td>时长</td>
              <td>
                <span>{{ baseAccount.date.month }}月</span>
                <span v-if="baseAccount.date.day > 0">
                  {{ baseAccount.date.day }}天
                </span>
              </td>
            </tr>
            <tr>
              <td>住院时间</td>
              <td>{{ baseAccount.live_time }}</td>
              <td>离院时间</td>
              <td>{{ baseAccount.leave_time }}</td>
            </tr>
            <tr></tr>
            <tr>
              <td>总金额</td>
              <td style="color: #ff8000;">{{ baseAccount.total_amount }}元</td>
              <td>实收金额</td>
              <td style="color: #f00;">{{ baseAccount.amount }}元</td>
            </tr>
          </table>
        </div>
        <el-divider v-if="jzAccount.length > 0"
                    content-position="left">
          记账消费
        </el-divider>
        <div v-if="jzAccount.length > 0"
             class="jzAccount accountTable">
          <table class="table2"
                 width="100%">
            <tr>
              <td>消费内容</td>
              <td>消费金额</td>
              <td>消费时间</td>
            </tr>
            <tr v-for="(item, index) in jzAccount"
                :key="index">
              <td>{{ item.remark }}</td>
              <td>{{ item.amount }}</td>
              <td>{{ item.action_time }}</td>
            </tr>
          </table>
        </div>
        <el-divider v-if="byjAccount.length > 0"
                    content-position="left">
          备用金消费
        </el-divider>
        <div v-if="byjAccount.length > 0"
             class="jzAccount accountTable">
          <table class="table2"
                 width="100%">
            <tr>
              <td>消费内容</td>
              <td>消费金额</td>
              <td>消费时间</td>
            </tr>
            <tr v-for="(item, index) in byjAccount"
                :key="index">
              <td>{{ item.remark }}</td>
              <td>{{ item.amount }}</td>
              <td>{{ item.action_time }}</td>
            </tr>
          </table>
        </div>
      </div>
    </el-dialog>
    <el-dialog width="70%"
               :title="`${healthTitle}测评记录`"
               :visible.sync="healthTableVisible"
               append-to-body
               :close-on-click-modal="false">
      <div style="padding-bottom: 10px">
        <el-button type="primary"
                   @click="handleAddHeal">添加健康测评</el-button>
      </div>
      <app-table :page-data="healthpageData"
                 :table-columns="tableHealthColumns"
                 :width="260"
                 @current-change="handleHealthCurrentChange">
        <template slot-scope="scope">
          <el-button size="mini"
                     type="success"
                     @click="handleHealthShowDetail(scope.row)"> 评估详情</el-button>
          <el-button size="mini"
                     type="primary"
                     @click="handleHealthDownload(scope.row)"> 下载</el-button>
          <el-button size="mini"
                     type="danger"
                     @click="handleHealthDelete(scope.row)"> 删除</el-button>
        </template>
      </app-table>
    </el-dialog>
    <el-dialog title="添加测评"
               :visible.sync="dialogHealthyVisible"
               :close-on-click-modal="false"
               width="60%"
               :append-to-body="true">
      <healthy-assess v-if="dialogHealthyVisible"
                      :data="typedata"
                      @close="dialogHealthyVisible = false"
                      @load="handleAddHealthLoad"></healthy-assess>
    </el-dialog>
    <el-dialog title="测评结果"
               :visible.sync="dialogResultVisible"
               width="30%"
               :close-on-click-modal="false"
               :append-to-body="true"
               :modal-append-to-body="true"
               class="dialogForm">
      <div class="item_ul">
        <div class="item">
          <div class="title">日常生活活动能力</div>
          <div class="text">
            {{healthresult.value1 | valueFormat}}
          </div>
        </div>
        <div class="item">
          <div class="title">精神状态</div>
          <div class="text">
            {{healthresult.value2 | valueFormat}}
          </div>
        </div>
        <div class="item">
          <div class="title">感知与沟通能力</div>
          <div class="text">
            {{healthresult.value3 | valueFormat}}
          </div>
        </div>
        <div class="item">
          <div class="title">社会参与能力</div>
          <div class="text">
            {{healthresult.value4 | valueFormat}}
          </div>
        </div>
        <div class="item">
          <div class="title">综合评定</div>
          <div class="text">
            {{healthresult.value5 | valueFormat}}
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import appTable from "@/components/AppTable/index";
import commonForm from "@/components/CommonForm/index";
import leaveAccountForm from "@/components/CommonForm/leaveAccoutForm";
import leaveDetailForm from "@/components/CommonForm/leaveDetailForm";
import accountDetail from "./components/accountDetail";
import leaveForm from "./components/leaveForm";
import healthyAssess from "@/components/CommonForm/healthy-assess";
import * as APIHealthAssessment from "@/api/healthAssessment";
import { unixToDate } from "@/utils";
import {
  getList,
  feesDetail,
  cancelFees,
  billList,
  setNoBill,
  payBill,
  setRecover,
  findAllBill,
  getelderhealthtest,
  getebill,
  ebillresult,
  elderback,
} from "@/api/oldermanager";
import appMap from "@/components/AppMap/index";
export default {
  name: "Index",
  components: {
    appTable,
    commonForm,
    leaveAccountForm,
    appMap,
    leaveDetailForm,
    accountDetail,
    leaveForm,
    healthyAssess,
  },
  filters: {
    valueFormat(value) {
      if (value == 0) {
        return "能力完好";
      } else if (value == 1) {
        return "轻度受损";
      } else if (value == 2) {
        return "中度受损";
      } else if (value >= 3) {
        return "重度受损";
      } else {
        return "评估不准确";
      }
    },
  },
  data() {
    return {
      keyword: "",
      addIndex: 0,
      map: null,
      key: Math.random(),
      key2: Math.random(),
      key3: Math.random(),
      key4: Math.random(),
      showAdd: true,
      mapVisible: false,
      accountTable: false,
      dialogVisible: false,
      dialogVisibleLive: false,
      dialogVisibleNurse: false,
      innerVisibleNurse: false,
      innerVisibleAccount: false,
      dialogVisibleAccount: false,
      dialogVisibleDetailLive: false,
      base: {},
      formData: {
        base: {},
      },
      xfForm: {},
      accountForm: {},
      appFormData: {},
      currentSelectedData: [],
      pageData: {},
      innerPageData: {
        page: 1,
        total: 0,
        page_size: 5,
        list: [],
      },
      accountPageData: {
        page: 1,
        total: 0,
        page_size: 5,
        list: [],
      },
      selectForm: {},
      baseAccount: {
        bed: {},
        care: {},
        meal: {},
        date: {},
      },
      jzAccount: [],
      byjAccount: [],
      innerSelectForm: {},
      accountSelectForm: {},
      dataPickerBeforeTodayOptions: {
        disabledDate(time) {},
      },
      tableColumns: [
        { prop: "name", label: "姓名", width: 100 },
        { prop: "age", label: "年龄", width: 100 },
        {
          prop: "sex",
          label: "性别",
          formatter: this.genderFormatter,
          width: 100,
        },
        { prop: "mobile", label: "联系方式", width: 150 },
        { prop: "id_card", label: "身份证", width: 200 },
        { prop: "in_type", label: "老人类别", formatter: this.intypeFormatter },
        { prop: "floor_str", label: "床位号" },
        {
          prop: "status",
          label: "入住状态",
          formatter: this.statusFormatter,
        },
        {
          prop: "jia",
          label: "是否请假",
          formatter: this.leaveFormatter,
        },
        {
          prop: "live_time",
          label: "入住时间",
          formatter: this.liveFormatter,
          width: 100,
        },
      ],
      tableColumns2: [
        { prop: "amount", label: "金额" },
        { prop: "action_time", label: "时间" },
        { prop: "remark", label: "消费内容" },
        { prop: "status", label: "状态", formatter: this.feesFormatter },
        { prop: "final_amount", label: "当前余额" },
      ],
      tableColumns3: [
        { prop: "type", label: "账单类型", formatter: this.typeformatter },
        { prop: "type1", label: "消费类型", formatter: this.type1formatter },
        { prop: "amount", label: "金额" },
        { prop: "action_time", label: "时间" },
        { prop: "remark", label: "账单明细" },
      ],
      rules: {
        type: [{ required: true, message: "请输入账单类型", trigger: "blur" }],
        title: [{ required: true, message: "请输入账单名称", trigger: "blur" }],
        amount: [{ required: true, message: "请输入费用", trigger: "blur" }],
        action_time: [
          { required: true, message: "请选择时间", trigger: "change" },
        ],
        remark: [
          { required: true, message: "请输入消费内容", trigger: "blur" },
        ],
      },
      //测评记录
      healthTableVisible: false,
      dialogHealthyVisible: false,
      typedata: {},
      healthTitle: "",
      tableHealthColumns: [
        /* { prop: "source_name", label: "信息提供者" },
          { prop: "contact_name", label: "联系人姓名" },
          { prop: "contact_mobile", label: "联系人电话" },
          { prop: "cause", label: "评估原因", formatter: this.causeFormat },
          { prop: "test_result", label: "评估结果", formatter: this.valueFormat },
          { prop: "action_time", label: "评估时间" }, */
        { prop: "name", label: "姓名" },
        {
          prop: "review_time",
          label: "评估时间",
          formatter(row, column, cellValue) {
            return unixToDate(cellValue);
          },
        },
        {
          prop: "test_level",
          label: "评估结果",
          formatter(row, column, cellValue) {
            if (cellValue == 1) {
              return "能力完好";
            } else if (cellValue == 2) {
              return "轻度失能";
            } else if (cellValue == 3) {
              return "中度失能";
            } else if (cellValue == 4) {
              return "重度失能";
            } else if (cellValue == 5) {
              return "完全失能";
            } else {
              return "评估未完成";
            }
          },
        },
        {
          prop: "create_time",
          label: "添加时间",
          formatter(row, column, cellValue) {
            return unixToDate(cellValue);
          },
        },
        {
          prop: "update_time",
          label: "更新时间",
          formatter(row, column, cellValue) {
            return unixToDate(cellValue);
          },
        },
      ],
      healthpageData: {
        type: -1,
      },
      e_id: "",
      //测评结果
      dialogResultVisible: false,
      healthresult: {},
      //账单汇总
      accoutResult: {},
      formAccountData: {},
      //老人请假
      dialogVisibleLeave: false,
      leave_eid: "",
    };
  },
  created() {},
  beforeDestroy() {},
  mounted() {
    this.getTableData();
    // this.init();
  },
  methods: {
    handleIntype(e) {
      console.log(e);
      this.selectForm.in_type = e;
      this.getTableData();
    },
    //showdil
    showdil(bool) {
      this.dialogVisible = false;
    },
    typeformatter(row) {
      if (row.type == 1) {
        return "消费";
      } else if (row.type == 2) {
        return "交费";
      }
    },
    type1formatter(row) {
      if (row.type1 == 1) {
        return "床位费";
      } else if (row.type1 == 2) {
        return "餐费";
      } else if (row.type1 == 3) {
        return "护理费";
      } else if (row.type1 == 4) {
        return "管理费";
      } else {
        return "其他";
      }
    },
    //测评记录
    valueFormat(row) {
      if (row.test_result == 0) {
        return "能力完好";
      } else if (row.test_result == 1) {
        return "轻度受损";
      } else if (row.test_result == 2) {
        return "中度受损";
      } else if (row.test_result >= 3) {
        return "重度受损";
      } else {
        return "评估不准确";
      }
    },
    causeFormat(row) {
      if (row.cause == "1") {
        return "第一次评估";
      } else if (row.cause == "2") {
        return "常规评估";
      } else if (row.cause == "3") {
        return "状态变化后重新评估";
      }
    },
    handleHealthCurrentChange(val) {
      /* getelderhealthtest("get", {page: val, e_id: this.e_id}).then(res => {
          this.healthpageData = Object.assign(res.data, { type: -1 })
        }) */
      APIHealthAssessment.reviewOlder({ page: val, eid: this.e_id }).then(
        (res) => {
          this.healthpageData = Object.assign(res.data, { type: -1 });
        }
      );
    },
    handleViewData(data) {
      this.dialogResultVisible = true;
      this.healthresult = {
        value1: data.daily_result,
        value2: data.daily_result,
        value3: data.feel_result,
        value4: data.s_result,
        value5: data.test_result,
      };
    },
    handleHealthShowDetail(row) {
      const url = window.location.origin + "/exreview/info?id=" + row.id;
      window.open(url);
    },
    handleHealthDownload(row) {
      window.location.href =
        window.location.origin + "/exreview/upload?id=" + row.id;
    },
    handleHealthDelete(row) {
      this.$confirm("此操作将永久删除该信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          APIHealthAssessment.reviewDelete({ id: row.id }).then((res) => {
            if (res.code == 200) {
              this.$message({ type: "success", message: "删除成功!" });
              this.handleAddHealthLoad();
            }
          });
        })
        .catch(() => {});
    },
    dataDifference(endDate, startDate) {
      let dataSpan;
      let tempDate;
      let iDays;
      endDate = Date.parse(endDate);
      startDate = Date.parse(startDate);
      dataSpan = startDate - endDate;
      dataSpan = Math.abs(dataSpan);
      iDays = Math.floor(dataSpan / (24 * 3600 * 1000));
      return iDays + 1;
    },
    init() {
      this.map = new BMap.Map("mapStyle");
      this.map.centerAndZoom(new BMap.Point(114.07, 32.13), 8);
      // this.map.centerAndZoom(new BMap.Point(114.35, 34.79), 8);
      // 地图缩放控件
      this.map.setMapStyleV2({
        styleId: "0e5948460769123a23b5c7615b59ae9d",
      });
      this.myGeo = new BMap.Geocoder();
    },
    bdGEO() {
      if (this.addIndex < this.pageData.list.length) {
        var add = this.pageData.list[this.addIndex];
        this.geocodeSearch(add);
        this.addIndex++;
      }
    },
    geocodeSearch(add) {
      let _this = this;
      if (this.addIndex < this.pageData.list.length) {
        setTimeout(_this.bdGEO, 400);
      }
      this.myGeo.getPoint(
        add.address,
        function (point) {
          if (point) {
            var address = new BMap.Point(point.lng, point.lat);
            // console.log(address);
            console.log(
              "update elder set lat='" +
                address.lat +
                "',lng='" +
                address.lng +
                "' where id=" +
                add.id +
                ";"
            );
          }
        },
        "合肥市"
      );
    },
    statusFormatter(row, column) {
      if (row.status == -1) {
        return "已离院";
      } else if (row.status > 0) {
        return "正常";
      } else {
        return "无效信息";
      }
    },
    intypeFormatter(row, column) {
      if (row.in_type == 1) {
        return "智慧中心";
      } else if (row.in_type == 2) {
        return "养护中心";
      } else if (row.in_type == 3) {
        return "老年公寓";
      }
    },
    leaveFormatter(row) {
      if (row.jia == 0) {
        return "未请假";
      } else {
        return "请假中";
      }
    },
    genderFormatter(row, column) {
      if (row.sex == 1) {
        return "男";
      } else if (row.sex == 2) {
        return "女";
      }
    },
    liveFormatter(row, column) {
      if (row.live_time == 0) {
        return "暂无信息";
      } else {
        return row.live_time;
      }
    },
    feesFormatter(row, column) {
      if (row.status == 1) {
        return "已扣费";
      } else if (row.status == 2) {
        return "已退款";
      } else {
        return "无效记录";
      }
    },
    accountFormatter(row, column) {
      if (row.status == 1) {
        return "未结算";
      } else if (row.status == 2) {
        return "已结算";
      } else {
        return "无效";
      }
    },
    getFeesTable() {
      let data = this.innerSelectForm;
      ebillresult(data).then((resp) => {
        if (resp.code === 200) {
          this.accoutResult = resp?.data || {};
          this.dialogVisibleNurse = true;
        }
      });
    },
    accoutSearch(form) {
      Object.assign(this.innerSelectForm, form);
      this.getFeesTable();
    },
    getBillTable() {
      let data = this.accountSelectForm;
      getebill("get", data).then((resp) => {
        if (resp.code === 200) {
          this.accountPageData = resp.data;
          this.dialogVisibleAccount = true;
        }
      });
    },
    accountsearch() {
      this.getBillTable();
    },
    getTableData() {
      let data = this.selectForm;
      getList("get", data).then((resp) => {
        if (resp.code === 200) {
          this.pageData = resp.data;
          this.$set(this.pageData, "type", 2);
          // this.addIndex = 0;
          // this.bdGEO();
        }
      });
    },
    getALlBill(data) {
      findAllBill("get", data).then((resp) => {
        if (resp.code === 200) {
          console.log(resp.data);
          let data = resp.data;
          // this.accountTable = true;
          this.baseAccount = data.fees;
          this.jzAccount = data.list;
          this.byjAccount = data.fees_list;
          let day = this.dataDifference(
            this.baseAccount.date.start_time,
            this.baseAccount.date.end_time
          );
          console.log(day);
          this.$set(this.baseAccount, "day", day);
        }
      });
    },
    blllDetail(rows) {
      console.log(rows);
      let id = rows.rows[0].id;
      let params = {
        e_id: id,
      };
      this.getALlBill(params);
    },
    handleAdd() {
      this.key = Math.random();
      this.dialogVisible = true;
      this.formData = { base: {} };
    },
    handleDelete() {
      if (this.currentSelectedData.length === 0) {
        this.$message({
          message: "请选择一条您要删除的内容",
          type: "warning",
        });
      } else if (this.currentSelectedData.length > 1) {
        this.$message({
          message: "一次只能删除一条内容",
          type: "warning",
        });
      } else {
        this.$confirm("此操作将永久删除该信息, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.formData = Object.assign({}, this.currentSelectedData[0]);
            let param = {
              id: this.formData.id,
            };
            getList("delete", param).then((resp) => {
              if (resp.code === 200) {
                this.$message({
                  type: "success",
                  message: "删除成功!",
                });
                this.getTableData();
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
            });
          });
      }
    },
    handleCheckedRows(rows) {
      if (rows && rows instanceof Array && rows.length > 0) {
        this.currentSelectedData = rows;
      } else {
        this.currentSelectedData = [];
      }
    },
    handleCurrentChange(val) {
      this.selectForm.page = val;
      this.getTableData();
    },
    handleCurrentChange1(val) {
      this.accountSelectForm.page = val;
      this.getBillTable();
    },
    handleCheck() {
      if (this.currentSelectedData.length === 0) {
        this.$message({
          message: "请选择一条您要查看的内容",
          type: "warning",
        });
      } else if (this.currentSelectedData.length > 1) {
        this.$message({
          message: "一次只能查看一条内容",
          type: "warning",
        });
      } else {
        let params = {
          id: this.currentSelectedData[0].id,
        };
        getList("get", params).then((resp) => {
          if (resp.code === 200) {
            this.formData = resp.data;
            this.base = resp.data.base;
            this.dialogVisible = true;
            this.key = Math.random();
          }
        });
      }
    },
    handleOldLeave() {
      this.key3 = Math.random();
      if (this.currentSelectedData.length === 0) {
        this.$message({
          message: "请选择一条您要查看的内容",
          type: "warning",
        });
      } else if (this.currentSelectedData.length > 1) {
        this.$message({
          message: "一次只能查看一条内容",
          type: "warning",
        });
      } else {
        this.dialogVisibleLeave = true;
        this.leave_eid = this.currentSelectedData[0].id;
      }
    },
    leave(rows) {
      let params = {
        id: rows.rows[0].id,
      };
      getList("get", params).then((resp) => {
        if (resp.code === 200) {
          this.formData = resp.data;
          this.base = resp.data.base;
          this.dialogVisibleLive = true;
          this.key3 = Math.random();
        }
      });
      ebillresult({ e_id: rows.rows[0].id }).then((resp) => {
        if (resp.code === 200) {
          this.accoutResult = resp?.data || {};
        }
      });
    },
    elderback(rows) {
      this.$confirm("是否重新入住?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let params = {
            e_id: rows.rows[0].id,
          };
          elderback(params).then((resp) => {
            if (resp.code === 200) {
              this.formData = resp.data;
              this.base = resp.data.elder;
              this.dialogVisible = true;
              this.key = Math.random();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    leavedetail(rows) {
      let params = {
        id: rows.rows[0].id,
      };
      getList("get", params).then((resp) => {
        if (resp.code === 200) {
          this.formData = resp.data;
          this.base = resp.data.base;
          this.dialogVisibleDetailLive = true;
          this.key4 = Math.random();
        }
      });
    },
    cancelLeave(data) {
      // this.dialogVisibleLive = false;
      // this.dialogVisibleDetailLive = false;
      if (data) {
        this.getTableData();
      }
      this.dialogVisibleLive = false;
    },
    changeLeave(params) {
      ebillresult(params).then((resp) => {
        if (resp.code === 200) {
          this.accoutResult = resp?.data || {};
        }
      });
    },
    closeDialogLive() {
      this.dialogVisibleLive = false;
      this.dialogVisibleDetailLive = false;
      this.showAdd = true;
    },
    closeDialog() {
      this.dialogVisible = false;
      this.getTableData();
      this.formData = { base: {} };
    },
    handleMap(keyword) {
      this.key2 = Math.random();
      this.mapVisible = true;
      if (keyword) this.keyword = keyword;
    },
    closeMap() {
      this.mapVisible = false;
    },
    result(e) {
      this.mapVisible = false;
      this.$set(this.base, "lng", e.lng);
      this.$set(this.base, "lat", e.lat);
      this.$set(this.base, "address", e.address);
      this.$set(this.formData, "base", this.base);
    },
    search() {
      this.selectForm.page = 1;
      this.getTableData();
    },
    consumption(data) {
      this.innerSelectForm.e_id = data.rows[0].id;
      let params = {
        e_id: data.rows[0].id,
      };
      this.key2 = Math.random();
      this.getFeesTable();
      // this.getALlBill(params);
      this.formAccountData = data.rows[0];
    },
    handleAddNurse() {
      this.innerVisibleNurse = true;
      this.$set(this.xfForm, "e_id", this.innerSelectForm.e_id);
    },
    handleDeleteNurse(id) {
      this.$confirm("确定返还费用, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let params = {
            id: id,
          };
          cancelFees("post", params).then((resp) => {
            if (resp.code === 200) {
              this.$message({
                type: "success",
                message: "已返还费用",
              });
              this.getFeesTable();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消返还费用",
          });
        });
    },
    saveNurse() {
      this.$refs["xfForm"].validate(async (valid) => {
        if (valid) {
          feesDetail("post", this.xfForm).then((resp) => {
            if (resp.code === 200) {
              this.$message({
                type: "success",
                message: "添加成功",
              });
              this.cancelXf("xfForm");
              this.getFeesTable();
            }
          });
        }
      });
    },
    cancelXf(formName) {
      this.$refs[formName].resetFields();
      this.xfForm = {};
      this.innerVisibleNurse = false;
    },
    closeDialogNurse() {
      this.dialogVisibleNurse = false;
    },
    closeDialogLeave() {
      this.dialogVisibleLeave = false;
      this.$refs.dataTable.$refs.dataTable.clearSelection();
    },
    handleCancleLeave() {
      this.dialogVisibleLeave = false;
      this.currentSelectedData = [];
      this.$refs.dataTable.$refs.dataTable.clearSelection();
    },
    closeVisibleNurse() {
      this.innerVisibleNurse = false;
    },
    handleInnerCurrentChange(val) {
      this.innerSelectForm.page = val;
    },
    checkDetail(id) {
      this.dialogVisibleNurse = true;
      this.innerSelectForm.e_id = id;
      this.getFeesTable();
      this.showAdd = false;
    },
    accountTk(data) {
      this.accountSelectForm.e_id = data.rows[0].id;
      this.getBillTable();
    },
    handleGetQuestions(data) {
      this.healthTableVisible = true;
      this.healthTitle = data.name;
      this.e_id = data.id;
      /* getelderhealthtest("get", {e_id: data.id}).then(res => {
          this.healthpageData = Object.assign(res.data, { type: -1 })
        }) */
      APIHealthAssessment.reviewOlder({ eid: data.id }).then((res) => {
        this.healthpageData = Object.assign(res.data, { type: -1 });
      });
    },
    handleAddHeal() {
      this.dialogHealthyVisible = true;
      this.typedata = { ...{ name: this.healthTitle, eid: this.e_id } };
    },
    handleAddHealthLoad() {
      this.handleHealthCurrentChange(1);
    },
    handleAddAccount() {
      this.$set(this.accountForm, "e_id", this.accountSelectForm.e_id);
      this.innerVisibleAccount = true;
    },
    handleSelectionChange(rows) {
      this.currentSelectedData = [];
      for (let index = 0; index < rows.length; index++) {
        const element = rows[index];
        this.currentSelectedData.push(element.id);
      }
    },
    handleSettlement() {
      //结算
      if (this.currentSelectedData.length === 0) {
        this.$message({
          type: "warning",
          message: "至少选择一条结算信息",
        });
        return false;
      }
      let idString = this.currentSelectedData.join(",");
      let params = {
        id: idString,
      };
      payBill("post", params).then((resp) => {
        if (resp.code === 200) {
          this.$message({
            type: "success",
            message: "已结算",
          });
          this.canceAccount("accountForm");
          this.getBillTable();
        }
      });
    },
    handleCancelAccount(id) {
      this.$confirm("确定删除此账单, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let params = {
            id: id,
          };
          getebill("post", params).then((resp) => {
            if (resp.code === 200) {
              this.$message({
                type: "success",
                message: "已删除成功",
              });
              this.getBillTable();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消操作",
          });
        });
    },
    saveAccount() {
      this.$refs["accountForm"].validate(async (valid) => {
        if (valid) {
          getebill("post", this.accountForm).then((resp) => {
            if (resp.code === 200) {
              this.$message({
                type: "success",
                message: "添加成功",
              });
              this.canceAccount("accountForm");
              this.getBillTable();
            }
          });
        }
      });
    },
    closeVisibleAccount() {
      this.innerVisibleAccount = false;
    },
    closeDialogAccount() {
      this.dialogVisibleAccount = false;
    },
    canceAccount(formName) {
      this.$refs[formName].resetFields();
      this.accountForm = {};
      this.innerVisibleAccount = false;
    },
    set_cell_style({ row, column, rowIndex, columnIndex }) {
      if (columnIndex == 3) {
        if (row.status == 1) {
          return "green-cell";
        } else if (row.status == 2) {
          return "red-cell";
        } else {
          return "yellow-cell";
        }
      }
    },
    set_cell_style2({ row, column, rowIndex, columnIndex }) {
      // if (columnIndex == 4) {
      //   if (row.status == 1) {
      //     return "yellow-cell";
      //   } else if (row.status == 2) {
      //     return "green-cell ";
      //   } else {
      //     return "red-cell";
      //   }
      // }
    },
    handlePrint() {
      console.log(111);
      this.$print(this.$refs.print);
    },
  },
};
</script>
<style lang="scss" scoped>
.index-container {
  box-sizing: border-box;
  width: 100%;
  padding: 0 30px !important;
  margin: 0 !important;
  background: #fff !important;

  .main-header {
    padding-top: 4px;
    padding-bottom: 10px;
    .search {
      width: 100%;

      .search-title {
        flex: 0 0 48px;
        width: 48px;
        font-size: 16px;
        line-height: 36px;
        color: #333;
      }
    }
  }

  .form-footer {
    padding-left: 100px;
  }

  .dialog-main {
    .table-do {
      margin-bottom: 15px;
    }

    ::v-deep {
      th {
        .cell {
          color: #fff;
        }
      }
    }
  }

  .el-table {
    ::v-deep {
      .red-cell div {
        color: #fff;
        background: rgba($color: #f00, $alpha: 1);
      }

      .green-cell div {
        color: #fff;
        background: green;
      }

      .blue-cell div {
        color: #fff;
        background: rgb(64, 158, 255);
      }

      .yellow-cell div {
        color: #fff;
        background: #ff8000;
      }

      .red-cell-font div {
        color: rgba($color: #f00, $alpha: 0.5);
      }
    }
  }
}

.table {
  width: 100%;
  color: #666;
  border-collapse: collapse;
  background-color: #fff;

  td {
    position: relative;
    min-height: 20px;
    padding: 9px 15px;
    font-size: 14px;
    line-height: 20px;
    border: 1px solid #e6e6e6;

    &:nth-child(odd) {
      width: 20%;
      text-align: right;
      background-color: #f7f7f7;
    }
  }
}

.table2 {
  width: 100%;
  color: #666;
  border-collapse: collapse;
  background-color: #fff;

  tr {
    &:first-child {
      position: relative;
      min-height: 20px;
      padding: 9px 15px;
      font-size: 14px;
      line-height: 20px;
      background-color: #f7f7f7;
      border: 1px solid #e6e6e6;
    }
  }

  td {
    position: relative;
    min-height: 20px;
    padding: 9px 15px;
    font-size: 14px;
    line-height: 20px;
    text-align: center;
    border: 1px solid #e6e6e6;

    &:nth-child(odd) {
      /* width: 20%; */

      /* text-align: right; */
    }
  }
}

.printBtn {
  margin-bottom: 20px;
  text-align: right;
}

.accountTable {
  margin-bottom: 30px;
}

.el-divider {
  ::v-deep {
    .el-divider__text {
      font-size: 16px;
      color: #ff8000;
    }
  }
}
.item_ul {
  padding: 0 24px;

  .item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;

    .title {
      font-size: 16px;
      color: #999999;
    }

    .text {
      color: #333;
      font-size: 16px;
    }
  }
}
</style>
